//
//  RHDeviceTopoME_215EUView.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/6/9.
//

#import "RHDeviceTopoME_215EUView.h"
#import "RHDeviceTopoBatteryItemView.h"
#define line_Width 1
@interface RHDeviceTopoME_215EUView()

//电网功率
@property (nonatomic, strong) QMUILabel *gridLab;

//电池功率
@property (nonatomic, strong) QMUILabel *batteryPowerLab;
//负载功率
@property (nonatomic, strong) QMUILabel *loadLab;

//pcs功率
@property (nonatomic, strong) QMUILabel *pcsLab;
//acdc1功率
@property (nonatomic, strong) QMUILabel *acdc1Lab;
//acdc2功率
@property (nonatomic, strong) QMUILabel *acdc2Lab;
//mppt1功率
@property (nonatomic, strong) QMUILabel *mppt1Lab;
//mppt2功率
@property (nonatomic, strong) QMUILabel *mppt2Lab;
//mppt3功率
@property (nonatomic, strong) QMUILabel *mppt3Lab;
//pv1功率
@property (nonatomic, strong) QMUILabel *pv1Lab;
//pv2功率
@property (nonatomic, strong) QMUILabel *pv2Lab;
//pv3功率
@property (nonatomic, strong) QMUILabel *pv3Lab;



@property (nonatomic, strong) UIImageView *gridImg;

@property (nonatomic, strong) UIImageView *generatorImg;

@property (nonatomic, strong) UIImageView *batteryImg;

@property (nonatomic, strong) UIImageView *loadImg;

@property (nonatomic, strong) UIImageView *ATSImg;

@property (nonatomic, strong) UIImageView *transformerImg;

@property (nonatomic, strong) UIImageView *pcsImg;

@property (nonatomic, strong) UIImageView *acdc1Img;
@property (nonatomic, strong) UIImageView *acdc2Img;

@property (nonatomic, strong) UIImageView *mppt1Img;
@property (nonatomic, strong) UIImageView *mppt2Img;
@property (nonatomic, strong) UIImageView *mppt3Img;

@property (nonatomic, strong) UIImageView *pv1Img;
@property (nonatomic, strong) UIImageView *pv2Img;
@property (nonatomic, strong) UIImageView *pv3Img;

//光伏圆点
@property (nonatomic ,strong) UIView *pv1DotView;
@property (nonatomic ,strong) UIView *pv2DotView;
@property (nonatomic ,strong) UIView *pv3DotView;
//电网圆点
@property (nonatomic ,strong) UIView *grid1DotView;
@property (nonatomic ,strong) UIView *grid2DotView;
//并网电网圆点
@property (nonatomic ,strong) UIView *parallel_gridDotView;
//负载圆点
@property (nonatomic ,strong) UIView *loadDotView;
//电池圆点
@property (nonatomic ,strong) UIView *batteryDotView;
//发电机圆点
@property (nonatomic ,strong) UIView *generatorDotView;

//光伏动画
@property (nonatomic ,strong) UIBezierPath *pv1Path;
@property (nonatomic ,strong) UIBezierPath *pv2Path;
@property (nonatomic ,strong) UIBezierPath *pv3Path;
//负载动画
@property (nonatomic ,strong) UIBezierPath *loadPath;
//电网
@property (nonatomic ,strong) UIBezierPath *grid1Path;
@property (nonatomic ,strong) UIBezierPath *grid2Path;
//电池动画
@property (nonatomic ,strong) UIBezierPath *batteryPath;
//发电机动画
@property (nonatomic ,strong) UIBezierPath *generationPath;


@property (nonatomic ,assign) BOOL isLandscape;


@property (nonatomic ,strong) NSArray *batViewArr;

@property (nonatomic ,strong) UIView *paralellView;

@property (nonatomic ,strong) UIView *itemContainView;

@property (nonatomic, assign) NSInteger scroll_index;

@property (nonatomic ,strong) UIScrollView *scrollView;

@end
@implementation RHDeviceTopoME_215EUView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        self.backgroundColor = [UIColor whiteColor];
     
        [self setupUI];
    }
    return self;
}

-(instancetype)initWithOrientation:(BOOL)isLandscape
{
    if(self = [super initWithFrame:CGRectZero]){
        self.backgroundColor = [UIColor whiteColor];
        self.isLandscape = isLandscape;
        [self setupUI];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setNeedsDisplay];
}


-(void)setupUI
{
    CGFloat valueFont = 12;
    CGFloat itemSize = 32;
    kWeakSelf;
    UIColor *titleColor = kCOLOR_HEX_A(@"#171A1D", 0.6);
    //发电机
    UIImageView *generatorImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_Generator"]];
    [self addSubview:generatorImg];
    self.generatorImg = generatorImg;
    [generatorImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(@(CGSizeMake(32, 32)));
        make.left.mas_offset(20);
        make.top.mas_offset(20);
    }];
    
    QMUILabel *generatorTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    generatorTitleLab.text = @"Generator";
    [self addSubview:generatorTitleLab];
    [generatorTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(generatorImg.mas_bottom).offset(5);
        make.left.equalTo(generatorImg.mas_left);
    }];
    
    
    //ATS
    UIImageView *AtsImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_ATS"]];
    [self addSubview:AtsImg];
    self.ATSImg = AtsImg;
    [AtsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(@(CGSizeMake(itemSize, itemSize)));
        make.centerX.mas_offset(0);
        make.top.equalTo(generatorImg);
    }];
    
    QMUILabel *atsTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    atsTitleLab.text = @"ATS";
    [self addSubview:atsTitleLab];
    [atsTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(AtsImg.mas_bottom).offset(0);
        make.left.equalTo(AtsImg.mas_left).offset(-30);
    }];
    
    
    //负载
    UIImageView *loadImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_Load"]];
    [self addSubview:loadImg];
    self.loadImg = loadImg;
    [loadImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.top.equalTo(generatorImg);
        make.right.mas_offset(-25);
    }];
    
    QMUILabel *loadTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    loadTitleLab.text = @"Load";
    [self addSubview:loadTitleLab];
    [loadTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(loadImg.mas_bottom).offset(0);
        make.left.equalTo(loadImg.mas_left);
    }];
    
    _loadLab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _loadLab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_loadLab];
    [_loadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(loadTitleLab.mas_bottom).offset(2);
        make.left.equalTo(loadImg.mas_left).offset(0);
    }];
    
    //transformer
    UIImageView *transformerImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_Transformer"]];
    [self addSubview:transformerImg];
    self.transformerImg = transformerImg;
    [transformerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.top.equalTo(AtsImg.mas_bottom).offset(60);
        make.centerX.mas_offset(0);
    }];
    
    QMUILabel *transformerTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    transformerTitleLab.text = @"Transformer";
    [self addSubview:transformerTitleLab];
    [transformerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(transformerImg.mas_bottom).offset(2);
        make.left.equalTo(transformerImg.mas_right).offset(10);
    }];
    
    //PCS
    UIImageView *pcsImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_PCS"]];
    [self addSubview:pcsImg];
    self.pcsImg = pcsImg;
    [pcsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.top.equalTo(transformerImg.mas_bottom).offset(60);
        make.centerX.mas_offset(0);
    }];
    
    QMUILabel *pcsTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    pcsTitleLab.text = @"PCS";
    [self addSubview:pcsTitleLab];
    [pcsTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pcsImg).offset(2);
        make.right.equalTo(pcsImg.mas_left).offset(-10);
    }];
    
    _pcsLab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _pcsLab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_pcsLab];
    [_pcsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pcsTitleLab.mas_bottom).offset(2);
        make.right.equalTo(pcsTitleLab);
    }];
    
    //ACDC1
    UIImageView *acdc1Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_ACDC"]];
    [self addSubview:acdc1Img];
    self.acdc1Img = acdc1Img;
    [acdc1Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.top.equalTo(pcsImg.mas_bottom).offset(60);
        make.left.mas_offset(20);
    }];
    
    QMUILabel *acdc1TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    acdc1TitleLab.text = @"ACDC1";
    [self addSubview:acdc1TitleLab];
    [acdc1TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pcsImg.mas_bottom).offset(0);
        make.left.equalTo(acdc1Img).offset(2);
    }];
    
    _acdc1Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _acdc1Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_acdc1Lab];
    [_acdc1Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(acdc1TitleLab.mas_bottom).offset(2);
        make.left.equalTo(acdc1TitleLab);
    }];
    
    //ACDC2
    UIImageView *acdc2Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_ACDC"]];
    [self addSubview:acdc2Img];
    self.acdc2Img = acdc2Img;
    [acdc2Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(acdc1Img);
        make.top.equalTo(acdc1Img);
        make.left.equalTo(acdc1Img.mas_right).offset(itemSize);
    }];
    
    QMUILabel *acdc2TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    acdc2TitleLab.text = @"ACDC2";
    [self addSubview:acdc2TitleLab];
    [acdc2TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(acdc2Img.mas_bottom).offset(2);
        make.left.equalTo(acdc2Img.mas_centerX).offset(3);
    }];
    
    _acdc2Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _acdc2Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_acdc2Lab];
    [_acdc2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(acdc2TitleLab.mas_bottom).offset(2);
        make.left.equalTo(acdc2TitleLab);
    }];
    
    
    //电网
    UIImageView *gridImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_Grid"]];
    [self addSubview:gridImg];
    self.gridImg = gridImg;
    [gridImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.left.equalTo(acdc1Img.mas_right);
        make.top.equalTo(weakSelf.acdc1Img.mas_bottom).offset(40);
    }];
    
    QMUILabel *gridTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    gridTitleLab.text = @"Grid";
    [self addSubview:gridTitleLab];
    [gridTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(gridImg.mas_bottom).offset(5);
        make.left.equalTo(gridImg);
    }];
    
    _gridLab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _gridLab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_gridLab];
    [_gridLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(gridTitleLab);
        make.top.equalTo(gridTitleLab.mas_bottom).offset(2);
    }];
    
    //mppt1
    UIImageView *mppt1Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_MPPT"]];
    [self addSubview:mppt1Img];
    self.mppt1Img = mppt1Img;
    [mppt1Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.left.equalTo(pcsImg.mas_right);
        make.top.equalTo(weakSelf.acdc1Img);
    }];
    
    _mppt1Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _mppt1Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_mppt1Lab];
    [_mppt1Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mppt1Img);
        make.bottom.equalTo(mppt1Img.mas_top).offset(-30);
    }];
    
    QMUILabel *mppt1TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    mppt1TitleLab.text = @"DCDC1";
    [self addSubview:mppt1TitleLab];
    [mppt1TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mppt1Lab.mas_top).offset(-3);
        make.left.equalTo(weakSelf.mppt1Lab);
    }];
    
    //mppt2
    UIImageView *mppt2Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_MPPT"]];
    [self addSubview:mppt2Img];
    self.mppt2Img = mppt2Img;
    [mppt2Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.left.equalTo(mppt1Img.mas_right).offset(15);
        make.top.equalTo(weakSelf.acdc1Img);
    }];
    
    _mppt2Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _mppt2Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_mppt2Lab];
    [_mppt2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mppt2Img);
        make.bottom.equalTo(mppt2Img.mas_top).offset(-30);
    }];
    
    QMUILabel *mppt2TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    mppt2TitleLab.text = @"DCDC2";
    [self addSubview:mppt2TitleLab];
    [mppt2TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mppt2Lab.mas_top).offset(-3);
        make.left.equalTo(weakSelf.mppt2Lab);
    }];
    
    //mppt3
    UIImageView *mppt3Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_MPPT"]];
    [self addSubview:mppt3Img];
    self.mppt3Img = mppt3Img;
    [mppt3Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.left.equalTo(mppt2Img.mas_right).offset(15);
        make.top.equalTo(weakSelf.acdc1Img);
    }];
    
    _mppt3Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _mppt3Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_mppt3Lab];
    [_mppt3Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mppt3Img);
        make.bottom.equalTo(mppt3Img.mas_top).offset(-30);
    }];
    
    QMUILabel *mppt3TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    mppt3TitleLab.text = @"DCDC3";
    [self addSubview:mppt3TitleLab];
    [mppt3TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mppt3Lab.mas_top).offset(-3);
        make.left.equalTo(weakSelf.mppt3Lab);
    }];
    
    //pv1
    UIImageView *pv1Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_pv"]];
    [self addSubview:pv1Img];
    self.pv1Img = pv1Img;
    [pv1Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.centerX.equalTo(mppt1Img);
        make.top.equalTo(weakSelf.mppt1Img.mas_bottom).offset(20);
    }];
    
    QMUILabel *pv1TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    pv1TitleLab.text = @"PV1";
    [self addSubview:pv1TitleLab];
    [pv1TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv1Img);
        make.top.equalTo(pv1Img.mas_bottom).offset(2);
    }];
    
    _pv1Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _pv1Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_pv1Lab];
    [_pv1Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv1TitleLab);
        make.top.equalTo(pv1TitleLab.mas_bottom).offset(2);
    }];
    
    //pv2
    UIImageView *pv2Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_pv"]];
    [self addSubview:pv2Img];
    self.pv2Img = pv2Img;
    [pv2Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.centerX.equalTo(mppt2Img);
        make.top.equalTo(weakSelf.mppt2Img.mas_bottom).offset(20);
    }];
    
    QMUILabel *pv2TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    pv2TitleLab.text = @"PV2";
    [self addSubview:pv2TitleLab];
    [pv2TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv2Img);
        make.top.equalTo(pv2Img.mas_bottom).offset(2);
    }];
    
    _pv2Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _pv2Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_pv2Lab];
    [_pv2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv2TitleLab);
        make.top.equalTo(pv2TitleLab.mas_bottom).offset(2);
    }];
    
    //pv3
    UIImageView *pv3Img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_topo_215_EU_pv"]];
    [self addSubview:pv3Img];
    self.pv3Img = pv3Img;
    [pv3Img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(generatorImg);
        make.centerX.equalTo(mppt3Img);
        make.top.equalTo(weakSelf.mppt3Img.mas_bottom).offset(20);
    }];
    
    QMUILabel *pv3TitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    pv3TitleLab.text = @"PV3";
    [self addSubview:pv3TitleLab];
    [pv3TitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv3Img);
        make.top.equalTo(pv3Img.mas_bottom).offset(2);
    }];
    
    _pv3Lab = [QMUILabel labelWithFont:kSYSTEMFONT(valueFont) textColor:kCOLOR_HEX(@"#3F4443")];
    _pv3Lab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    [self addSubview:_pv3Lab];
    [_pv3Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pv3TitleLab);
        make.top.equalTo(pv3TitleLab.mas_bottom).offset(2);
    }];
    
    //并机
    UIView *paralellView = [[UIView alloc]init];
//    paralellView.backgroundColor = kCOLOR_HEX(@"e0e0e0");
    [self addSubview:paralellView];
    self.paralellView = paralellView;
    [paralellView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (!weakSelf.isLandscape) {
            make.top.equalTo(weakSelf.gridLab.mas_bottom).offset(20);
        }
        
        make.left.right.mas_offset(0);
        make.height.offset(120);
        make.bottom.mas_offset(0);
    }];
    
    _scrollView = [[UIScrollView alloc]init];
//    scrollView.backgroundColor = UIColor.yellowColor;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.delegate = self;
    [paralellView addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    _itemContainView = [[UIView alloc]init];
//    _itemContainView.backgroundColor = UIColor.blueColor;
    [_scrollView addSubview:_itemContainView];
    [_itemContainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    NSMutableArray *arr = [NSMutableArray array];
    //最多8个并机
    for (int i = 0; i<8; i++) {
        RHDeviceTopoBatteryItemView *batView = [[RHDeviceTopoBatteryItemView alloc]init];
//        batView.backgroundColor = kRandomColor;
        [arr addObject:batView];
        [self.itemContainView addSubview:batView];
    }
    
    //上面的横线
    UIView *line_horizontal = kView;
    line_horizontal.backgroundColor = kCOLOR_HEX_A(@"#5AD8A6", 1);
    line_horizontal.tag = 400;
    [_itemContainView addSubview:line_horizontal];
    self.batViewArr = arr.copy;
    
    
    //------ 小圆点
    _pv1DotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_pv1DotView setBackgroundColor:kCOLOR_HEX_A(@"#F9C626", 1)];
    [_pv1DotView.layer setCornerRadius:3];
    [self addSubview:_pv1DotView];
    
    _pv2DotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_pv2DotView setBackgroundColor:kCOLOR_HEX_A(@"#F9C626", 1)];
    [_pv2DotView.layer setCornerRadius:3];
    [self addSubview:_pv2DotView];
    
    _pv3DotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_pv3DotView setBackgroundColor:kCOLOR_HEX_A(@"#F9C626", 1)];
    [_pv3DotView.layer setCornerRadius:3];
    [self addSubview:_pv3DotView];
    
    _grid1DotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_grid1DotView setBackgroundColor:kCOLOR_HEX_A(@"#42D5EA", 1)];
    [_grid1DotView.layer setCornerRadius:3];
    [self addSubview:_grid1DotView];
    
    _grid2DotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_grid2DotView setBackgroundColor:kCOLOR_HEX_A(@"#42D5EA", 1)];
    [_grid2DotView.layer setCornerRadius:3];
    [self addSubview:_grid2DotView];
    
    _parallel_gridDotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_parallel_gridDotView setBackgroundColor:kCOLOR_HEX_A(@"#7073F0", 1)];
    [_parallel_gridDotView.layer setCornerRadius:3];
    [self addSubview:_parallel_gridDotView];
    
    _loadDotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_loadDotView setBackgroundColor:kCOLOR_HEX_A(@"#F9A4A3", 1)];
    [_loadDotView.layer setCornerRadius:3];
    [self addSubview:_loadDotView];
    
    _batteryDotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_batteryDotView setBackgroundColor:kCOLOR_HEX_A(@"#76D16E", 1)];
    [_batteryDotView.layer setCornerRadius:3];
    [self addSubview:_batteryDotView];

    _generatorDotView = [[UIView alloc] initWithFrame:CGRectMake(-200, 0, 6, 6)];
    [_generatorDotView setBackgroundColor:kCOLOR_HEX_A(@"#678EF2", 1)];
    [_generatorDotView.layer setCornerRadius:3];
    [self addSubview:_generatorDotView];

    
   //全屏布局
  
}

-(UIView*)batViewWithIndex:(NSInteger)index
{
    UIView *batView = kView;
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX(@"5AD8A6");
    [batView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(1);
        make.centerX.mas_offset(0);
        make.top.mas_offset(0);
        make.height.offset(20);
    }];
    
    UIImageView *borderImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_paralell_dashBorder"]];
    [batView addSubview:borderImage];
    [borderImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(@(CGSizeMake(54, 54)));
        make.centerX.mas_offset(0);
        make.top.equalTo(line.mas_bottom);
    }];
    
    QMUILabel *socLab = [QMUILabel labelWithFont:kSYSTEMFONT(8) textColor:kCOLOR_HEX(@"5AD8A6") textAligment:NSTextAlignmentCenter];
    socLab.text = @"--%";
    socLab.tag = 100 + index;
    [borderImage addSubview:socLab];
    [socLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.mas_offset(5);
    }];
    
    UIImageView *batteryImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_paralell_batteryIcon"]];
    [borderImage addSubview:batteryImg];
    [batteryImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(@(CGSizeMake(19, 30)));
        make.centerX.mas_offset(0);
        make.bottom.mas_offset(-5);
    }];
    

    
    QMUILabel *batteryTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6) textAligment:NSTextAlignmentLeft];
    batteryTitleLab.text = @"Power";
    [batView addSubview:batteryTitleLab];
    [batteryTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(borderImage.mas_bottom).offset(5);
        make.left.equalTo(borderImage);
    }];
    
    QMUILabel *batteryPowerLab = [QMUILabel labelWithFont:kSYSTEMFONT(12) textColor:kCOLOR_HEX(@"#3F4443") textAligment:NSTextAlignmentLeft];
    batteryPowerLab.text = @"--W";
    batteryPowerLab.tag = 200 + index;
    [batView addSubview:batteryPowerLab];
    [batteryPowerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(batteryTitleLab);
        make.top.equalTo(batteryTitleLab.mas_bottom).offset(5);
        make.bottom.mas_offset(-5);
    }];


    return batView;
}

- (void)drawRect:(CGRect)rect
{
    //-------- 连线 generator -->ats
    UIBezierPath *generator_ats = [UIBezierPath bezierPath];
    generator_ats.lineWidth = line_Width;
   
    [kCOLOR_HEX(@"FF9AAB") setStroke];
    [generator_ats moveToPoint:CGPointMake(self.generatorImg.right, self.generatorImg.centerY)];
    [generator_ats addLineToPoint:CGPointMake(self.ATSImg.left , self.ATSImg.centerY)];
    [generator_ats stroke];
    self.generationPath = generator_ats;
 
    //-------- 连线  ats -->load
    UIBezierPath *ats_load = [UIBezierPath bezierPath];
    ats_load.lineWidth = line_Width;
   
    [kCOLOR_HEX(@"#A3D57C")  setStroke];
    [ats_load moveToPoint:CGPointMake(self.ATSImg.right, self.ATSImg.centerY)];
    [ats_load addLineToPoint:CGPointMake(self.loadImg.left , self.loadImg.centerY)];
    [ats_load stroke];
    self.loadPath = ats_load;
    

    //-------- 连线  ats --> transformer
    UIBezierPath *ats_transformer = [UIBezierPath bezierPath];
    ats_transformer.lineWidth = line_Width;
    [kCOLOR_HEX(@"#58C0A8") setStroke];
    [ats_transformer moveToPoint:CGPointMake(self.ATSImg.centerX, self.ATSImg.bottom)];
    [ats_transformer addLineToPoint:CGPointMake(self.transformerImg.centerX , self.transformerImg.top)];
   
    [ats_transformer stroke];
    
    
    //-------- 连线  transformer --> pcs
    UIBezierPath *transformer_pcs = [UIBezierPath bezierPath];
    transformer_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#D49152") setStroke];
    [transformer_pcs moveToPoint:CGPointMake(self.transformerImg.centerX, self.transformerImg.bottom )];
    [transformer_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.top)];
    [transformer_pcs stroke];
   

    
    //-------- 连线  acdc1 --> pcs
    UIBezierPath *acdc1_pcs = [UIBezierPath bezierPath];
    acdc1_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [acdc1_pcs moveToPoint:CGPointMake(self.acdc1Img.centerX , self.acdc1Img.top)];
    [acdc1_pcs addLineToPoint:CGPointMake(self.acdc1Img.centerX , self.pcsImg.bottom+30+5)];
    [acdc1_pcs addArcWithCenter:CGPointMake(self.acdc1Img.centerX+5, self.pcsImg.bottom+30+5) radius:5 startAngle:M_PI endAngle:M_PI+M_PI_2 clockwise:YES];
    [acdc1_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom+30)];
    [acdc1_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom)];
    [acdc1_pcs stroke];
   
    //-------- 连线  acdc2 --> pcs
    UIBezierPath *acdc2_pcs = [UIBezierPath bezierPath];
    acdc2_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [acdc2_pcs moveToPoint:CGPointMake(self.acdc2Img.centerX , self.acdc2Img.top)];
    [acdc2_pcs addLineToPoint:CGPointMake(self.acdc2Img.centerX , self.pcsImg.bottom+30)];
    [acdc2_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.bottom+30)];
    [acdc2_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom)];
  
    
    
    
    [acdc2_pcs stroke];

    
    
    //-------- 连线  grid --> acdc1
    UIBezierPath *grid_acdc1 = [UIBezierPath bezierPath];
    grid_acdc1.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [grid_acdc1 moveToPoint:CGPointMake(self.gridImg.centerX , self.gridImg.top)];
    [grid_acdc1 addLineToPoint:CGPointMake(self.gridImg.centerX , self.acdc1Img.bottom+20)];
    [grid_acdc1 addLineToPoint:CGPointMake(self.acdc1Img.centerX+5, self.acdc1Img.bottom+20)];
    [grid_acdc1 addArcWithCenter:CGPointMake(self.acdc1Img.centerX+5, self.acdc1Img.bottom+15) radius:5 startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
    [grid_acdc1 addLineToPoint:CGPointMake(self.acdc1Img.centerX , self.acdc1Img.bottom)];
   
    [grid_acdc1 stroke];

    
    
    //-------- 连线  grid --> acdc2
    UIBezierPath *grid_acdc2 = [UIBezierPath bezierPath];
    grid_acdc2.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [grid_acdc2 moveToPoint:CGPointMake(self.gridImg.centerX , self.gridImg.top)];
    [grid_acdc2 addLineToPoint:CGPointMake(self.gridImg.centerX , self.acdc2Img.bottom+20)];
    [grid_acdc2 addLineToPoint:CGPointMake(self.acdc2Img.centerX-5, self.acdc2Img.bottom+20)];
    [grid_acdc2 addArcWithCenter:CGPointMake(self.acdc2Img.centerX-5, self.acdc2Img.bottom+15) radius:5 startAngle:M_PI_2 endAngle:0 clockwise:NO];
    [grid_acdc2 addLineToPoint:CGPointMake(self.acdc2Img.centerX , self.acdc2Img.bottom)];
    [grid_acdc2 stroke];
 
    
    
    //-------- 连线  mpp1 --> pcs
    UIBezierPath *mppt1_pcs = [UIBezierPath bezierPath];
    mppt1_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [mppt1_pcs moveToPoint:CGPointMake(self.mppt1Img.centerX , self.mppt1Img.top)];
    [mppt1_pcs addLineToPoint:CGPointMake(self.mppt1Img.centerX , self.pcsImg.bottom+30)];
    [mppt1_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.bottom+30)];
    [mppt1_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom)];
   
    
    [mppt1_pcs stroke];
  
    
    //-------- 连线  mppt2 --> pcs
    UIBezierPath *mppt2_pcs = [UIBezierPath bezierPath];
    mppt2_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [mppt2_pcs moveToPoint:CGPointMake(self.mppt2Img.centerX , self.mppt2Img.top)];
    [mppt2_pcs addLineToPoint:CGPointMake(self.mppt2Img.centerX , self.pcsImg.bottom+30)];
    [mppt2_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.bottom+30)];
    [mppt2_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom)];
    
    [mppt2_pcs stroke];
 
    
    //-------- 连线  mppt3 --> pcs
    UIBezierPath *mppt3_pcs = [UIBezierPath bezierPath];
    mppt3_pcs.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [mppt3_pcs moveToPoint:CGPointMake(self.mppt3Img.centerX , self.mppt3Img.top)];
    [mppt3_pcs addLineToPoint:CGPointMake(self.mppt3Img.centerX , self.pcsImg.bottom+30+5)];
    [mppt3_pcs addArcWithCenter:CGPointMake(self.mppt3Img.centerX-5, self.pcsImg.bottom+30+5) radius:5 startAngle:0 endAngle:-M_PI_2 clockwise:NO];
    [mppt3_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.bottom+30)];
    [mppt3_pcs addLineToPoint:CGPointMake(self.pcsImg.centerX , self.pcsImg.bottom)];
   
    
    [mppt3_pcs stroke];
 
    
    //-------- 连线  pv1 --> mppt1
    UIBezierPath *pv1_mppt1 = [UIBezierPath bezierPath];
    pv1_mppt1.lineWidth = line_Width;
    [kCOLOR_HEX(@"#F8CF57") setStroke];
    [pv1_mppt1 moveToPoint:CGPointMake(self.pv1Img.centerX , self.pv1Img.top)];
    [pv1_mppt1 addLineToPoint:CGPointMake(self.mppt1Img.centerX, self.mppt1Img.bottom)];
    [pv1_mppt1 stroke];
  
    
    //-------- 连线  pv2 --> mppt2
    UIBezierPath *pv2_mppt2 = [UIBezierPath bezierPath];
    pv2_mppt2.lineWidth = line_Width;
    [kCOLOR_HEX(@"#F8CF57") setStroke];
    [pv2_mppt2 moveToPoint:CGPointMake(self.pv2Img.centerX , self.pv2Img.top)];
    [pv2_mppt2 addLineToPoint:CGPointMake(self.mppt2Img.centerX, self.mppt2Img.bottom)];
    [pv2_mppt2 stroke];
   
    
    //-------- 连线  pv3 --> mppt3
    UIBezierPath *pv3_mppt3 = [UIBezierPath bezierPath];
    pv3_mppt3.lineWidth = line_Width;
    [kCOLOR_HEX(@"#F8CF57") setStroke];
    [pv3_mppt3 moveToPoint:CGPointMake(self.pv3Img.centerX , self.pv3Img.top)];
    [pv3_mppt3 addLineToPoint:CGPointMake(self.mppt3Img.centerX, self.mppt3Img.bottom)];
    [pv3_mppt3 stroke];
   
    
    
    //-------- 连线  pcs --> battery
    UIBezierPath *pcs_battery = [UIBezierPath bezierPath];
    pcs_battery.lineWidth = line_Width;
    [kCOLOR_HEX(@"#91ADF6") setStroke];
    [pcs_battery moveToPoint:CGPointMake(self.pcsImg.centerX, self.pcsImg.bottom)];
    [pcs_battery addLineToPoint:CGPointMake(self.pcsImg.centerX , self.paralellView.top)];
    [pcs_battery stroke];
    self.batteryPath = pcs_battery;
   
    //发电机路径
    self.generationPath = [UIBezierPath bezierPath];;
    [self.generationPath appendPath:generator_ats];
    
    //电网
    self.grid1Path = [UIBezierPath bezierPath];
    [self.grid1Path appendPath:grid_acdc1];
    [self.grid1Path appendPath:acdc1_pcs];
  
    self.grid2Path = [UIBezierPath bezierPath];
    [self.grid2Path appendPath:grid_acdc2];
    [self.grid2Path appendPath:acdc2_pcs];
    
    //光伏
    self.pv1Path = [UIBezierPath bezierPath];
    [self.pv1Path appendPath:pv1_mppt1];
    [self.pv1Path appendPath:mppt1_pcs];
    
    self.pv2Path = [UIBezierPath bezierPath];
    [self.pv2Path appendPath:pv2_mppt2];
    [self.pv2Path appendPath:mppt2_pcs];
    
    self.pv3Path = [UIBezierPath bezierPath];
    [self.pv3Path appendPath:pv3_mppt3];
    [self.pv3Path appendPath:mppt3_pcs];
    
    //有时设置数据源时 路径还没生成
   
    [self updateMicroGridAnimation];
    
}

//设备进来  //只有电池才除以1000
-(void)setTopoModel:(RHTopoModel *)topoModel deviceModel:(nonnull RHDeviceModel *)deviceModel
{
    kWeakSelf;
    [self setNeedsDisplay];
    self.topoModel = topoModel;
    self.deviceModel = deviceModel;
    
    //测试
//    self.deviceModel.status = @"0";
//    self.topoModel.loadPwr = @"9";
//    self.topoModel.acDc1Power = @"1";
//    self.topoModel.acDc2Power = @"2";
//    self.topoModel.batPwr = @"5";
//    self.topoModel.pv1 = @"3";
//    self.topoModel.pv2 = @"4";
//    self.topoModel.pv3 = @"5";
//    self.topoModel.dcDc1Power = @"6";
//    self.topoModel.dcDc2Power = @"7";
//    self.topoModel.dcDc3Power = @"8";
    //设备在线但逆变器离线 图标置灰
  
    
    //-------------------------------------------------------------------------
    
    self.pv1Lab.attributedText        = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    self.gridLab.attributedText         = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    self.loadLab.attributedText         = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    self.batteryPowerLab.attributedText = [NSString attributeStringWithContent:@"--kW" attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    
   
    BOOL isOnline = [self.deviceModel.status isEqualToString:@"0"];
    
    
    [self updateBatView];
    [self setNeedsDisplay];
    //设备离线
   
    if(!isOnline) return;
   
    
    //电池功率
    NSDecimalNumber *batteryPower = [NSDecimalNumber decimalNumberWithDouble:[topoModel.batPwr doubleValue]];
    self.batteryPowerLab.text = [NSString stringWithFormat:@"%@kW",batteryPower];
    
    
    //逆变器离线只显示电池数据
//    if (self.deviceModel.invState == 0) {
//        return;
//    }
    
    //光伏功率
    NSString *solarStr = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.pvPwr doubleValue]]];
    self.pv1Lab.attributedText = [NSString attributeStringWithContent:solarStr attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    
    //电网功率
    NSString *gridStr = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.gridPwr doubleValue]]];
    self.gridLab.attributedText = [NSString attributeStringWithContent:gridStr attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    
    //负载功率
    NSString *loadStr = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.loadPwr doubleValue]]];
    self.loadLab.attributedText = [NSString attributeStringWithContent:loadStr attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    //负载功率
    NSString *pcsStr = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.pcsPwr doubleValue]]];
    self.pcsLab.attributedText = [NSString attributeStringWithContent:pcsStr attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
   //ACDC
    NSString *acdc1Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.acDc1Power doubleValue]]];
    self.acdc1Lab.attributedText = [NSString attributeStringWithContent:acdc1Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    NSString *acdc2Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.acDc2Power doubleValue]]];
    self.acdc2Lab.attributedText = [NSString attributeStringWithContent:acdc2Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    //mppt
    NSString *mppt1Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.dcDc1Power doubleValue]]];
    self.mppt1Lab.attributedText = [NSString attributeStringWithContent:mppt1Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    NSString *mppt2Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.dcDc2Power doubleValue]]];
    self.mppt2Lab.attributedText = [NSString attributeStringWithContent:mppt2Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    NSString *mppt3Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.dcDc3Power doubleValue]]];
    self.mppt3Lab.attributedText = [NSString attributeStringWithContent:mppt3Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    //光伏
    NSString *pv1Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.pv1Pwr doubleValue]]];
    self.pv1Lab.attributedText = [NSString attributeStringWithContent:pv1Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    NSString *pv2Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.pv2Pwr doubleValue]]];
    self.pv2Lab.attributedText = [NSString attributeStringWithContent:pv2Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
    
    NSString *pv3Str = [NSString stringWithFormat:@"%@ kW",[NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:[topoModel.pv3Pwr doubleValue]]];
    self.pv3Lab.attributedText = [NSString attributeStringWithContent:pv3Str attriFont:kSYSTEMFONT(8) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.6) attriKey:@"kW"];
}

#pragma mark -------- 微网的动画和户用的方向相反
-(void)updateMicroGridAnimation
{
    if(![self.deviceModel.status isEqualToString:@"0"]) return;
    //电池动画  电池正值  电池流向逆变器  电池负值    逆变器流向电池
    if([_topoModel.batPwr floatValue]<-1){
        self.batteryDotView.hidden = NO;
        [self addAnimationWithPointView:self.batteryDotView path:self.batteryPath duration:3 animationName:@"battery"];
    }else if ([_topoModel.batPwr floatValue] > 1){
        self.batteryDotView.hidden = NO;
        [self addAnimationWithPointView:self.batteryDotView path:self.batteryPath.bezierPathByReversingPath duration:3 animationName:@"battery_rever"];
    }else{
        [self.batteryDotView.layer removeAllAnimations];
    }
    
    //光伏动画
    if([_topoModel.pv1Pwr floatValue]>1){
        self.pv1DotView.hidden = NO;
        [self addAnimationWithPointView:self.pv1DotView path:self.pv1Path duration:3 animationName:@"pv1"];
    }else{
        [self.pv1DotView.layer removeAllAnimations];
    }
    
    if([_topoModel.pv2Pwr floatValue]>1){
        self.pv2DotView.hidden = NO;
        [self addAnimationWithPointView:self.pv2DotView path:self.pv2Path duration:3 animationName:@"pv2"];
    }else{
        [self.pv2DotView.layer removeAllAnimations];
    }
    
    if([_topoModel.pv3Pwr floatValue]>1){
        self.pv3DotView.hidden = NO;
        [self addAnimationWithPointView:self.pv3DotView path:self.pv3Path duration:3 animationName:@"pv3"];
    }else{
        [self.pv3DotView.layer removeAllAnimations];
    }
    
   //电网动画  正(买电):grid---->inverter    负(卖电):inverter -----> grid
    if ([_topoModel.acDc1Power floatValue]> 1){
        self.grid1DotView.hidden = NO;
        [self addAnimationWithPointView:self.grid1DotView path:self.grid1Path duration:3 animationName:@"grid_rever1"];
    }else{
        [self.grid1DotView.layer removeAllAnimations];
    }
    
    if ([_topoModel.acDc2Power floatValue]> 1){
        self.grid2DotView.hidden = NO;
        [self addAnimationWithPointView:self.grid2DotView path:self.grid2Path duration:3 animationName:@"grid_rever2"];
    }else{
        [self.grid2DotView.layer removeAllAnimations];
    }
    
    
    //负载动画
    if([_topoModel.loadPwr floatValue]>1){
        self.loadDotView.hidden = NO;
        [self addAnimationWithPointView:self.loadDotView path:self.loadPath duration:3 animationName:@"load"];
    }else{
        [self.loadDotView.layer removeAllAnimations];
    }
    
    //发电机动画
    if(_topoModel.genStatus){
        self.generatorDotView.hidden = NO;
        [self addAnimationWithPointView:self.generatorDotView path:self.generationPath duration:3 animationName:@"genrator"];
    }else{
        [self.generatorDotView.layer removeAllAnimations];
    }
}

//更新并机数量
-(void)updateBatView
{
   
    [self.batViewArr enumerateObjectsUsingBlock:^(UIView*  _Nonnull itemView, NSUInteger idx, BOOL * _Nonnull stop) {
            [itemView removeFromSuperview];
    }];
    //每页放4个
    CGFloat itemWidth = ( MIN(kUI_WINDOW_W, kUI_WINDOW_H)  - 30 - 20 )/4;
    __block UIView *lastView;
  
    NSInteger deviceCount = self.topoModel.batteryList.count>0?self.topoModel.batteryList.count:1;
    for (int i = 0; i<deviceCount; i++) {
        RHDeviceTopoBatteryItemView *batView = [self.batViewArr safeObjectAtIndex:i];
    
        NSDictionary *dic = [self.topoModel.batteryList safeObjectAtIndex:i];
        
        [batView setDataDic:dic mainDeviceId:self.deviceModel.deviceId status:[self.deviceModel.status integerValue]==0];
        
        [self.itemContainView addSubview:batView];
        if (lastView) {
            [batView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(lastView.mas_right).offset(0);
                make.size.equalTo(lastView);
                make.top.bottom.mas_offset(0);
            }];
        }else{
            [batView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(0);
                make.width.offset(itemWidth);
                make.top.bottom.mas_offset(0);
            }];
        }
        lastView = batView;
    }
    UIView *firstItem = [self.batViewArr firstObject];
    UIView *lastItem = [self.batViewArr safeObjectAtIndex:self.topoModel.batteryList.count-1];
    if (lastItem == nil) {
        lastItem = firstItem;
    }
    
    UIView *line_horizontal = [self.itemContainView viewWithTag:400];
    [line_horizontal mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.left.equalTo(firstItem.mas_centerX);
        make.right.equalTo(lastItem.mas_centerX);
        make.height.offset(1);
    }];
    [self.itemContainView bringSubviewToFront:line_horizontal];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(0);
    }];
    
    //不足4个 或者是全屏 居中排列
    if (self.topoModel.batteryList.count<4 || self.isLandscape) {
        [self.itemContainView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_offset(0);
            make.centerX.mas_offset(0);
        }];
    }else{
        [self.itemContainView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
    }
}




-(void)addAnimationWithPointView:(UIView*)pointView path:(UIBezierPath*)path duration:(NSTimeInterval)duration animationName:(NSString*)name
{
    [pointView.layer removeAllAnimations];
    CAKeyframeAnimation *pointAnimation = [self createAnimationWithPath:path duration:duration];
    [pointView.layer addAnimation:pointAnimation forKey:name];
}

-(CAKeyframeAnimation*)createAnimationWithPath:(UIBezierPath*)path duration:(NSTimeInterval)duration
{
    CAKeyframeAnimation *keyFrameAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    keyFrameAni.path = path.CGPath;
    keyFrameAni.removedOnCompletion = NO;
    keyFrameAni.duration = duration;
    keyFrameAni.repeatCount = MAXFLOAT;
    keyFrameAni.calculationMode = kCAAnimationPaced;;
    
    return keyFrameAni;
}

@end
